package com.kzd.sdk.ui.fragment;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.kzd.sdk.base.OwnerFragment;
import com.kzd.sdk.callback.KZD_HttpCallback;
import com.kzd.sdk.core.KZD_ApiManager;
import com.kzd.sdk.entity.KZD_GameRebate;
import com.kzd.sdk.utils.AppUtils;

public class KZD_RebateSurfaceFragment extends OwnerFragment {

    private LinearLayout mLinearLayout;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private TextView tvSurfaceContext;


    private KZD_HttpCallback<KZD_GameRebate> callbackGameRebate = new KZD_HttpCallback<KZD_GameRebate>() {
        @Override
        public void onSuccess(KZD_GameRebate data) {
            String rebate = data.getGame().getRebate();
            tvSurfaceContext.setText(rebate.replace("\r", "\n"));
            mSwipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onError(String error) {
            toast(error);
            mSwipeRefreshLayout.setRefreshing(false);
        }
    };

    @Override
    public String getLayoutIdByName() {
        return "kzd_include_app_recycler";
    }

    @Override
    public void initView(View view) {
        view.findViewById(AppUtils.getId(mContext, "mRecyclerView"))
                .setVisibility(View.GONE);
        mSwipeRefreshLayout = view.findViewById(AppUtils.getId(mContext, "mSwipeRefreshLayout"));
        mSwipeRefreshLayout.setColorSchemeResources(AppUtils.getColorId(mContext, "kzd_2983ff"));
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                initData();
            }
        });

        mLinearLayout = view.findViewById(AppUtils.getId(mContext, "mLinearLayout"));
        NestedScrollView scrollView = new NestedScrollView(mContext);
        scrollView.setLayoutParams(new LinearLayout.LayoutParams(-1,-2));
        tvSurfaceContext = new TextView(mContext);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-1, -1);
        params.setMargins(AppUtils.dp2px(15f), AppUtils.dp2px(15f), AppUtils.dp2px(15f), AppUtils.dp2px(15f));
        tvSurfaceContext.setLayoutParams(params);
        tvSurfaceContext.setTextColor(Color.parseColor("#666666"));
        tvSurfaceContext.setTextSize(15f);
        scrollView.addView(tvSurfaceContext);
        mLinearLayout.addView(scrollView);
    }

    @Override
    public void initData() {
        KZD_ApiManager.httpRebateApplyList(callbackGameRebate);
    }
}
